﻿--[[
   @brief    isp menu(线路选择菜单)
   @author   hqzheng
   @version  1.0
   @date     2017-09-29
--]]

tiandao_isp_menu = 
{
    menu_id = 0;
    menu_h = 0;
    color_mode_ =  MainCommon.color_mode.kDark;

    init = function (parent_id)
        tiandao_isp_menu.menu_id = parent_id;
        local menu_ptr = ui_utility.get_ctrl_ptr_by_id(parent_id);
        if nil == menu_ptr then
            return;
        end
        menu_ptr:RemoveAll();

        local color_data_config = comm_center.call_service("SvrTGPConfigMgr_GetColorMode", {});
        if color_data_config ~= nil and color_data_config.color_mode ~=nil then
            tiandao_isp_menu.color_mode_ = color_data_config.color_mode;
        end;

        -- 联通item
        local liantong_id = tiandao_isp_menu.add_nor_item(
            menu_ptr, LoadStr("FRAME_BOTTOM_CHINA_UNICOM"));
        ui_utility.setproperty_by_id(liantong_id, "OnClick", "tiandao_isp_menu.on_click_liantong_item");
        tiandao_isp_menu.set_menu_top_item_bkg(liantong_id);

        -- 电信item
        local dianxin_id = tiandao_isp_menu.add_nor_item(
            menu_ptr, LoadStr("FRAME_BOTTOM_CHINA_TELECOM"));
        ui_utility.setproperty_by_id(dianxin_id, "OnClick", "tiandao_isp_menu.on_click_dianxin_item");
        tiandao_isp_menu.set_menu_nor_item_bkg(dianxin_id);

        -- 其他item
        local other_id = tiandao_isp_menu.add_nor_item(
            menu_ptr, LoadStr("FRAME_BOTTOM_AUTO"));
        ui_utility.setproperty_by_id(other_id, "OnClick", "tiandao_isp_menu.on_click_other_item");
        tiandao_isp_menu.set_menu_nor_item_bkg(other_id);

        local menu_ptr = ui_utility.get_ctrl_ptr_by_id(parent_id);
        if nil ~= menu_ptr then
            local menu_rc = menu_ptr:GetRectEx(TRUE,TRUE);
            tiandao_isp_menu.menu_h = menu_rc.bottom - menu_rc.top;
        end
    end;

    show = function (parent_id, is_show, off_set_x, off_set_y)
        tiandao_isp_menu.init(parent_id);
        if is_show then
            -- 移动到要显示的位置
            local menu_ptr = ui_utility.get_ctrl_ptr_by_id(parent_id);
            if nil ~= menu_ptr then
                local menu_rc = menu_ptr:GetRectEx(TRUE,TRUE);
                local menu_w = menu_rc.right - menu_rc.left;
                local menu_h = menu_rc.bottom - menu_rc.top;
                menu_rc.left = off_set_x;
                menu_rc.right = menu_rc.left + menu_w;
                menu_rc.top = off_set_y;
                menu_rc.bottom = menu_rc.top;

                menu_ptr:MoveEx(menu_rc,TRUE);
            end
            tiandao_isp_menu.show_animation(parent_id);
        else
            tiandao_isp_menu.hide_animation(parent_id);
        end
    end;

    set_menu_top_item_bkg = function (menu_item_id)
        ui_utility.setproperty_by_id(menu_item_id, "Background",
            "NONE");
        ui_utility.setproperty_by_id(menu_item_id, "BackgroundHover",
            "9IMAGES:bottom_bar\\bottom_bar.png?379,130,387,138;" .. 
            "bottom_bar\\bottom_bar.png?389,130,397,138;" .. 
            "bottom_bar\\bottom_bar.png?399,130,407,138;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?389,140,397,148;" .. 
            "bottom_bar\\bottom_bar.png?399,140,407,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?389,140,397,148;" .. 
            "bottom_bar\\bottom_bar.png?399,140,407,148;Stretch;0;");
        ui_utility.setproperty_by_id(menu_item_id, "BackgroundPressed", "NONE");
        if tiandao_isp_menu.color_mode_ == MainCommon.color_mode.kDark then
            ui_utility.setproperty_by_id(menu_item_id,
            "BackgroundHover", "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
            ui_utility.setproperty_by_id(menu_item_id,
            "BackgroundPressed", "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
        end;
    end;

    set_menu_bottom_item_bkg = function (menu_item_id)
        ui_utility.setproperty_by_id(menu_item_id, "Background", "NONE");
        ui_utility.setproperty_by_id(menu_item_id, "BackgroundHover",
            "9IMAGES:bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?389,140,397,148;" .. 
            "bottom_bar\\bottom_bar.png?399,140,407,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?389,140,397,148;" .. 
            "bottom_bar\\bottom_bar.png?399,140,407,148;" .. 
            "bottom_bar\\bottom_bar.png?379,150,387,158;" .. 
            "bottom_bar\\bottom_bar.png?389,150,397,158;" .. 
            "bottom_bar\\bottom_bar.png?399,150,407,158;Stretch;0;");
        ui_utility.setproperty_by_id(menu_item_id, "BackgroundPressed", "NONE");
        if tiandao_isp_menu.color_mode_ == MainCommon.color_mode.kDark then
            ui_utility.setproperty_by_id(menu_item_id,
            "BackgroundHover", "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
            ui_utility.setproperty_by_id(menu_item_id,
            "BackgroundPressed", "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
        end;
    end;

    set_menu_nor_item_bkg = function (menu_item_id)
        ui_utility.setproperty_by_id(menu_item_id, "Background", "NONE");
        ui_utility.setproperty_by_id(menu_item_id, "BackgroundHover", 
            "9IMAGES:bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;" .. 
            "bottom_bar\\bottom_bar.png?379,140,387,148;Stretch;0;");
        ui_utility.setproperty_by_id(menu_item_id, "BackgroundPressed", "NONE");
        if tiandao_isp_menu.color_mode_ == MainCommon.color_mode.kDark then
            ui_utility.setproperty_by_id(menu_item_id, "BackgroundHover",
            "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
            ui_utility.setproperty_by_id(menu_item_id,
            "BackgroundPressed", "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
        end;
    end;

    add_nor_item = function (menu_ptr, item_name)
        local item_id = 0;
        if nil ~= menu_ptr then
            local const_ui_str, str_holder = U8toCUIStr("wegame_mainframe\\MenuItem.tpf/TenioUILayout/UIObject/Children/UIObject?btnCfgItem");

            item_id = menu_ptr:AppendItem(const_ui_str);
            ui_utility.setproperty_by_id(item_id, "Caption", item_name);
            if tiandao_isp_menu.color_mode_ == MainCommon.color_mode.kLight then
                ui_utility.setproperty_by_id(item_id, "TextColor", "0x3c3c3c");
                ui_utility.setproperty_by_id(item_id, "TextColorHover", "0x3c3c3c");
                ui_utility.setproperty_by_id(item_id, "TextColorPressed", "0x3c3c3c");
                ui_utility.setproperty_by_id(item_id, "BackgroundHover", "NONE");
                ui_utility.setproperty_by_id(item_id, "BackgroundPressed", "NONE");
            else
                ui_utility.setproperty_by_id(item_id, "TextColor", "0xE6E6E6");
                ui_utility.setproperty_by_id(item_id, "TextColorHover", "0xE6E6E6");
                ui_utility.setproperty_by_id(item_id, "TextColorPressed", "0xE6E6E6");
                ui_utility.setproperty_by_id(item_id, "BackgroundHover", "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
                ui_utility.setproperty_by_id(item_id, "BackgroundPressed", "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;");
            end;
        end
        return item_id;
    end;

    on_click_liantong_item = function (uilib, control_id)
        base_utility.mainframe_report("isp_menu", "isp_menu_click", "liantong");
        local text = LoadStr("FRAME_BOTTOM_NETWORK")..LoadStr("FRAME_BOTTOM_CHINA_UNICOM"); --"连接网络：联通";
        tiandao_isp_menu.set_btn_txt(text);
        local data = {game_id = plugin_tool_panel.cur_game_id, select_isp = 2};
        comm_center.call_service("Svr_SetUserSelectISP", data);
    end;

    on_click_dianxin_item = function (uilib, control_id)
        base_utility.mainframe_report("isp_menu", "isp_menu_click", "dianxin");
        local text = LoadStr("FRAME_BOTTOM_NETWORK")..LoadStr("FRAME_BOTTOM_CHINA_TELECOM");
        tiandao_isp_menu.set_btn_txt(text);
        local data = {game_id = plugin_tool_panel.cur_game_id, select_isp = 1};
        comm_center.call_service("Svr_SetUserSelectISP", data);
    end;

    on_click_other_item = function (uilib, control_id)
        base_utility.mainframe_report("isp_menu", "isp_menu_click", "other"); 
        local text = LoadStr("FRAME_BOTTOM_NETWORK")..LoadStr("FRAME_BOTTOM_AUTO");
        tiandao_isp_menu.set_btn_txt(text);      
        local data = {game_id = plugin_tool_panel.cur_game_id, select_isp = 3};
        comm_center.call_service("Svr_SetUserSelectISP", data);
    end;

    show_animation = function (menu_id)
        local menu_ptr = ui_utility.get_ctrl_ptr_by_id(menu_id);
        if nil == menu_ptr then
            return;
        end

        menu_ptr:Show(TRUE);

        local menu_rc = menu_ptr:GetRectEx(TRUE,TRUE);

        -- 开始尺寸
        local resize_start_sz = SIZE:new_local();
        resize_start_sz.cx = menu_rc.right - menu_rc.left;
        resize_start_sz.cy = 0;

        -- 展开后的尺寸
        local resize_end_sz = SIZE:new_local();
        resize_end_sz.cx = menu_rc.right - menu_rc.left;
        resize_end_sz.cy = tiandao_isp_menu.menu_h;


        -- 缩放动画
        animation_utility.init(
            tiandao_isp_menu.menu_id,
            "Setting_menu_Resize", animation_utility.ANI_TYPE.ANI_SIZE);
        animation_utility.size_animation(
            tiandao_isp_menu.menu_id, resize_start_sz, resize_end_sz, 1, 0);

    end;

    hide_animation = function (menu_id)
        local menu_ptr = ui_utility.get_ctrl_ptr_by_id(menu_id);
        if nil ~= menu_ptr then
            menu_ptr:Show(FALSE);
        end
    end;

    on_resize_animation_end = function ()
    end;

    set_btn_txt = function (text)
        local btn_txt_id = ui_utility.get_ctrl_id_by_path(
            plugin_tool_panel.parent_id, "PluginToolPanelCtn\\TianDaoCnt\\BtnISPSelect");
        ui_utility.setproperty_by_id(btn_txt_id, "Caption", text);
    end;
};
